##################################################################
# File : lua/sim/wreckage.lua
# Description : Class for wreckage so it can get pushed around
# Author : GPG
##################################################################

local Prop = import('/lua/sim/Prop.lua').Prop

Wreckage = Class(Prop) {

    OnCreate = function(self)
        Prop.OnCreate(self)
        # Make it go away after a few seconds
        self.Trash = TrashBag()
        self.Trash:Add(ForkThread( function() WaitSeconds(10.0) self:Destroy() end ))
    end,
    
    OnDamage = function(self, data)
        self:DoTakeDamage(data)
    end,

    DoTakeDamage = function(self, data)
        local maxHealth = self:GetMaxHealth()
        self:AdjustHealth(-data.Amount)
        local health = self:GetHealth()
        if health <= 0 then
            self:Destroy()
        end
    end,
    
    OnCollisionCheck = function(self, other)
        if IsUnit(other) then
            return false
        else
            return true
        end
    end,
}